package com.jyun;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

public class CountListener implements HttpSessionListener {
    private int count=0;

    public void sessionCreated(HttpSessionEvent se) {
        count++;
        ServletContext context=se.getSession().getServletContext();
        Object ip= se.getSession().getAttribute("ip:");
        context.setAttribute("count",count);
        context.log("ip: "+ip);
        System.out.println("ip "+ip);
        context.log("当前在线 "+count+" 人");
        System.out.println("++"+count);
//        System.out.println(se.getSession().getId());
    }

    public void sessionDestroyed(HttpSessionEvent se) {
        count--;
        ServletContext context=se.getSession().getServletContext();
        context.setAttribute("count",count);
        context.log("当前在线 "+count+" 人");
        System.out.println("--"+count);
    }
}
